package com.wl.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value={"/b","/b1","/b2"})
public class BServlet extends HttpServlet {
    // 处理get请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("BServlet get...");
        // 1. 设置相应的内容
        resp.setContentType("text/html;charset=utf-8");
        // 2. 设置相应出去的字符编码
        resp.setCharacterEncoding("utf-8");
        // 3. 得到输出流
        PrintWriter out = resp.getWriter();
        // 4. 写网页
        out.write("<h1>你好客户，常来</h1>");
        // 5. 刷新
        out.flush();

        req.setAttribute("version","v2.0");
        req.setAttribute("author","haha");
        // 重定向
//        resp.sendRedirect("/c");
//        resp.sendRedirect("http://www.baidu.com");
    }

    // 处理post请求
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
        System.out.println("BServlet post...");
    }
}
